import { SPlayerItem } from "../../../../Message/Public/SPlayerItem";
import { ColorConfig } from "../ColorConfig";
import { ItemsUtil } from "../../view/shortcuts/item/ItemsUtil";
import { ItemInfo } from "./ItemInfo";
import { ItemExInfo } from "./ItemExInfo";
import { ItemConfig } from "../ItemConfig";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { EEquip } from "../../../../Message/Public/EEquip";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ECategory } from "../../../../Message/Public/ECategory";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { Tooltip } from "../../view/common/tooltip/Tooltip";
import { Cache } from "../../cache/Cache";
import { EquipmentToolTipData } from "./EquipmentToolTipData";
import { ToolTipCompareInfo } from "../../view/common/tooltip/skillRune/ToolTipCompareInfo";
import { NormalTooltip } from "../../view/common/tooltip/NormalTooltip";
import { PetEquipTooltipInfo } from "./PetEquipTooltipInfo";
import { PetMingItemData } from "../../view/pet/info/PetMingItemData";
import { MountEquipToolTipInfo } from "./MountEquipToolTipInfo";
import { ColorInfo } from "./ColorInfo";
import { EBind } from "../../../../Message/Public/EBind";
import { EProp } from "../../../../Message/Public/EProp";
type int = number;
//class ItemData
    
    export /* dynamic */ class ItemData
    {
        constructor(arg1)
        {
            
            var loc1=null;
            this._data = new SPlayerItem();
            if (typeof arg1 === "splayeritem") 
            {
                this.data = arg1;
            }
            else if (typeof arg1 === "int") 
            {
                loc1 = new SPlayerItem();
                loc1.itemCode = arg1;
                this.data = loc1;
            }
            return;
        }

        public get effectEx(): int
        {
            if (this.itemInfo) 
            {
                return this.itemInfo.item.effectEx;
            }
            return -1;
        }

        public get gasValue(): int
        {
            this._gasValue = this._itemInfo.item.gasValue;
            return this._gasValue;
        }

        public get wxShenglingLV(): int
        {
            if (this.itemExInfo) 
            {
                return this.itemExInfo.sl_lv;
            }
            return 0;
        }

        public get wxColor(): int
        {
            if (this.itemExInfo) 
            {
                return int(this.itemExInfo.wx_color);
            }
            return 0;
        }

        public get wxColorStr(): string
        {
            var loc1=null;
            if (this.itemExInfo) 
            {
                loc1 = ColorConfig.instance.getItemColorString(this.wxColor);
                return loc1;
            }
            return "";
        }

        public get wxEnergy(): int
        {
            if (this.itemExInfo) 
            {
                return int(this._itemExInfo.wx_energy);
            }
            return 0;
        }

        public get wxLevel(): int
        {
            if (this.itemExInfo) 
            {
                return int(this._itemExInfo.wx_level);
            }
            return 0;
        }

        public get wxLuck(): int
        {
            if (this.itemExInfo) 
            {
                return int(this._itemExInfo.wx_lucky);
            }
            return 0;
        }

        public get wxExp(): int
        {
            if (this.itemExInfo) 
            {
                return int(this._itemExInfo.wx_exp);
            }
            return 0;
        }

        public set itemAmount(arg1: int)
        {
            this._data.itemAmount = arg1;
            return;
        }

        public get runeSwallowCodes(): Array<any>
        {
            if (this.itemExInfo) 
            {
                return this.itemExInfo.rune_swallow;
            }
            return [];
        }

        public isHasIdentify(): Boolean
        {
            if (this.itemExInfo) 
            {
                return this.itemExInfo.al_ify_flg > 0;
            }
            return false;
        }

        public get magicWeaponScore(): int
        {
            return ItemsUtil.getMagicWeaponScore(this);
        }

        public get magicWeaponLv(): int
        {
            if (this.itemExInfo) 
            {
                return this.itemExInfo.al_lv;
            }
            return 0;
        }

        public get cdTime(): number
        {
            if (this._cdTime < 0) 
            {
                if (this._itemInfo) 
                {
                    this._cdTime = this._itemInfo.item.cdTime;
                }
            }
            return this._cdTime;
        }

        public set cdTime(arg1: number)
        {
            this._cdTime = arg1;
            return;
        }

        public get uid(): string
        {
            if (this._data) 
            {
                return this._data.uid;
            }
            return null;
        }

        public set uid(arg1: string)
        {
            this._data.uid = arg1;
            return;
        }

        public get itemAmount(): int
        {
            if (this._data) 
            {
                return this._data.itemAmount;
            }
            return -1;
        }

        public get magicWeaponExp(): int
        {
            if (this.itemExInfo) 
            {
                return this.itemExInfo.al_exp;
            }
            return 0;
        }

        public get bind(): int
        {
            if (this._itemInfo) 
            {
                return this._itemInfo.item.bind;
            }
            return -1;
        }

        public get modelId(): string
        {
            if (this._modelId) 
            {
                return this._modelId;
            }
            if (this._itemInfo) 
            {
                return this._itemInfo.modelId;
            }
            return "";
        }

        public set modelId(arg1: string)
        {
            this._modelId = arg1;
            return;
        }

        public get itemCode(): int
        {
            if (this._data) 
            {
                return this._data.itemCode;
            }
            return -1;
        }

        public get posType(): int
        {
            if (this._data) 
            {
                return this._data.posType;
            }
            return -1;
        }

        public set posType(arg1: int)
        {
            if (this._data) 
            {
                this._data.posType = arg1;
            }
            return;
        }

        public get playerId(): int
        {
            if (this._data) 
            {
                return this._data.playerId;
            }
            return -1;
        }

        public get jsStr(): string
        {
            if (this._data) 
            {
                return this._data.jsStr;
            }
            return "";
        }

        public set jsStr(arg1: string)
        {
            if (this._data) 
            {
                this._data.jsStr = arg1;
            }
            return;
        }

        public get itemInfo(): ItemInfo
        {
            return this._itemInfo;
        }

        public get itemExInfo(): ItemExInfo
        {
            return this._itemExInfo;
        }

        public set itemExInfo(arg1: ItemExInfo)
        {
            this._itemExInfo = arg1;
            return;
        }

        public setItemExInfo(arg1: Object): void
        {
            if (arg1) 
            {
                if (this._itemExInfo) 
                {
                    this._itemExInfo.clear();
                }
                else 
                {
                    this._itemExInfo = new ItemExInfo();
                }
                this._itemExInfo.putObject(arg1);
            }
            else 
            {
                this._itemExInfo = null;
            }
            return;
        }

        public get data(): SPlayerItem
        {
            return this._data;
        }

        public set data(arg1: SPlayerItem)
        {
            var loc1=null;
            this._data = arg1;
            this._name = null;
            this._url = null;
            this._modelId = null;
            if (this._data) 
            {
                this._itemInfo = ItemConfig.instance.getInfoByCode(this._data.itemCode);
                if (this._itemInfo) 
                {
                    this._color = this._itemInfo.item.color;
                }
                if (this._data.jsStr == "") 
                {
                    this.itemExInfo = null;
                }
                else 
                {
                    try 
                    {
                        this.setItemExInfo(JSON.deserialize(this._data.jsStr));
                    }
                    catch (e)
                    {
                    };
                    if (this._itemInfo && this._itemExInfo) 
                    {
                        if (this._itemInfo.type != EEquip._EEquipWing) 
                        {
                            if (this._itemInfo.type != EEquip._EEquipFashion) 
                            {
                                if (this._itemInfo.type != EEquip._EEquipFashionWeapon) 
                                {
                                    if (this._itemInfo.type != EEquip._EEquipFootPrint) 
                                    {
                                        if (this._itemInfo.type != EEquip._EEquipBubble) 
                                        {
                                            if (this._itemInfo.type != EEquip._EEquipSurround) 
                                            {
                                                if (this._itemInfo.type != EEquip._EEquipWaistBelt) 
                                                {
                                                    if (this._itemInfo.type == EEquip._EEquipElf) 
                                                    {
                                                        this._modelId = this.itemExInfo.cELFModelId;
                                                        loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bELFModel);
                                                    }
                                                }
                                                else 
                                                {
                                                    this._modelId = this.itemExInfo.cWBModelId;
                                                    loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bWBModel);
                                                }
                                            }
                                            else 
                                            {
                                                this._modelId = this.itemExInfo.cSUModelId;
                                                loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bSUModel);
                                            }
                                        }
                                        else 
                                        {
                                            this._modelId = this.itemExInfo.cbubbleModelId;
                                            loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bbubbleModel);
                                        }
                                    }
                                    else 
                                    {
                                        this._modelId = this.itemExInfo.cFootprintModelId;
                                        loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bFootprintModel);
                                    }
                                }
                                else 
                                {
                                    this._modelId = this.itemExInfo.cWeapFashionModelId;
                                    loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bWeaponFashionModel);
                                }
                            }
                            else 
                            {
                                this._modelId = this.itemExInfo.cFashionModelId;
                                loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bFashionModel);
                            }
                        }
                        else 
                        {
                            this._modelId = this.itemExInfo.cWingModelId;
                            loc1 = ItemConfig.instance.getInfoByCode(this.itemExInfo.bWindModel);
                        }
                        if (loc1) 
                        {
                            this._name = loc1.item.name;
                            this._url = loc1.url;
                        }
                    }
                }
            }
            return;
        }

        public get url(): string
        {
            if (this._url) 
            {
                return this._url;
            }
            return this._itemInfo.url;
        }

        public set url(arg1: string)
        {
            this._url = arg1;
            return;
        }

        public get codeUnbind(): int
        {
            if (this.bind == 1) 
            {
                return this._itemInfo.item.codeUnbind;
            }
            return this.itemCode;
        }

        public get color(): int
        {
            return this._color;
        }

        public set color(arg1: int)
        {
            this._color = arg1;
            return;
        }

        public get type(): int
        {
            if (this.itemInfo) 
            {
                return this.itemInfo.item.type;
            }
            return -1;
        }

        public get name(): string
        {
            if (this._name) 
            {
                return this._name;
            }
            return this._itemInfo.item.name;
        }

        public get htmlName(): string
        {
            if (this._name) 
            {
                return HTMLUtil.addColor(this._itemInfo.colorStr, this._name);
            }
            return this._itemInfo.htmlName;
        }

        public set name(arg1: string)
        {
            this._name = arg1;
            return;
        }

        public get category(): int
        {
            if (this.itemInfo) 
            {
                return this.itemInfo.item.category;
            }
            return -1;
        }

        public get refLockDic(): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc1=null;
            var loc2=0;
            if (!this._refLockDic) 
            {
                this._refLockDic = new Map<any, any> /* flash.utils.Dictionary */();
                if (this._itemExInfo) 
                {
                    loc1 = this._itemExInfo.ref_lock.split(",");
                    var loc3=0;
                    var loc4=loc1;
                    for(loc2 of loc4) 
                    {
                        this._refLockDic[loc2] = loc2;
                    }
                }
            }
            return this._refLockDic;
        }

        public getToolTipData(arg1: int=0)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=arg1;
            switch (loc4) 
            {
                case ItemData.ToolTipType_Pack:
                {
                    if (this.itemInfo.item.category == ECategory._ECategoryMount) 
                    {
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Mounts, this);
                    }
                    if (this.itemInfo.item.category == ECategory._ECategoryEquip || this.itemInfo.item.category == ECategory._ECategorySpiritEquip) 
                    {
                        loc1 = Cache.instance.pack.rolePackCache.getAllItemsEnabledCareer();
                        if (!this.equipmentToolTipData) 
                        {
                            this.equipmentToolTipData = new EquipmentToolTipData(this, loc1, true);
                        }
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, this.equipmentToolTipData);
                    }
                    if (ItemsUtil.isHolyRune(this)) 
                    {
                        return new ToolTipCompareInfo(Tooltip.ToolTipRenderType_HolyRune, this);
                    }
                    if (ItemsUtil.isRune(this)) 
                    {
                        return new ToolTipCompareInfo(NormalTooltip.ToolTipRenderType_NormalRune, this);
                    }
                    if (ItemsUtil.isMagicWeapon(this)) 
                    {
                        return new ToolTipCompareInfo(Tooltip.ToolTipRenderType_MagicWeapon, this);
                    }
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
                }
                case ItemData.ToolTipType_Mounts:
                {
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Mounts, this);
                }
                case ItemData.ToolTipType_Player:
                {
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, this);
                }
                case ItemData.ToolTipType_Forge:
                {
                    if (this.itemInfo.item.category == ECategory._ECategoryEquip) 
                    {
                        if (!this.equipmentToolTipData) 
                        {
                            loc1 = Cache.instance.pack.rolePackCache.getAllItemsEnabledCareer();
                            this.equipmentToolTipData = new EquipmentToolTipData(this, loc1, false, false);
                            if (this.equipmentToolTipData.isEquiped()) 
                            {
                                this.equipmentToolTipData.isShowEquipped = true;
                            }
                        }
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, this.equipmentToolTipData);
                    }
                    if (this.itemInfo.item.category == ECategory._ECategoryMount) 
                    {
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Mounts, this);
                    }
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
                }
                case ItemData.ToolTipType_Exchange:
                {
                    if (this.itemInfo.item.category == ECategory._ECategoryEquip) 
                    {
                        loc1 = Cache.instance.pack.rolePackCache.getAllItemsEnabledCareer();
                        (loc3 = new EquipmentToolTipData(this, loc1, true)).additionalInfo = this.additionalInfo;
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, loc3);
                    }
                    if (ItemsUtil.isHolyRune(this)) 
                    {
                        return new ToolTipCompareInfo(Tooltip.ToolTipRenderType_HolyRune, this, false);
                    }
                    if (ItemsUtil.isRune(this)) 
                    {
                        return new ToolTipCompareInfo(NormalTooltip.ToolTipRenderType_NormalRune, this, false);
                    }
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
                }
                case ItemData.ToolTipType_PetEquip:
                {
                    if (!this.petEquipmentToolTipData) 
                    {
                        this.petEquipmentToolTipData = new PetEquipTooltipInfo(this);
                    }
                    return new ToolTipInfo(NormalTooltip.ToolTipRenderType_PetEquip, this.petEquipmentToolTipData);
                }
                case ItemData.ToolTipType_PetLifeStyle:
                {
                    return new ToolTipInfo(NormalTooltip.ToolTipRenderType_PetLifeStyle, new PetMingItemData(this._data));
                }
                case ItemData.ToolTipType_PetLifeStyleEquip:
                {
                    loc2 = new PetMingItemData(this._data);
                    loc2.isShowNext = true;
                    return new ToolTipInfo(NormalTooltip.ToolTipRenderType_PetLifeStyle, loc2);
                }
                case ItemData.ToolTipType_MountEquip:
                {
                    if (!this.mountEquipmentToolTipData) 
                    {
                        this.mountEquipmentToolTipData = new MountEquipToolTipInfo(this);
                    }
                    return new ToolTipInfo(NormalTooltip.ToolTipRenderType_MountEquip, this.mountEquipmentToolTipData);
                }
                default:
                {
                    if (this.itemInfo.item.category == ECategory._ECategoryEquip) 
                    {
                        loc1 = Cache.instance.pack.rolePackCache.getAllItemsEnabledCareer();
                        return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, new EquipmentToolTipData(this, loc1));
                    }
                    return new ToolTipInfo(Tooltip.ToolTipRenderType_Item, this);
                }
            }
        }

        public getPackToolTip(): string
        {
            return [this.getNameTip(), this.getCategoryTip(), this.getTypeTip(), this.getCodeTip(), this.getIconTip(), this.getBindTip()].join("");
        }

        public getMountTooltip(): string
        {
            return [this.getNameTip(), this.getCategoryTip(), this.getTypeTip(), this.getCodeTip(), this.getIconTip(), this.getBindTip()].join("");
        }

        /* internal  */getColorInfo(): ColorInfo
        {
            return ColorConfig.instance.getItemColor(this.color);
        }

        /* internal  */getNameTip(): string
        {
            return HTMLUtil.addColor(this.itemInfo.item.name, this.getColorInfo().color) + "\r";
        }

        /* internal  */getCategoryTip(): string
        {
            return HTMLUtil.addColor("大类：" + this.itemInfo.item.category, "#00FF00") + "\r";
        }

        /* internal  */getTypeTip(): string
        {
            return HTMLUtil.addColor("小类：" + this.itemInfo.item.type, "#FFFFFF") + "\r";
        }

        /* internal  */getCodeTip(): string
        {
            return HTMLUtil.addColor("Code:" + this.itemInfo.item.code, "#FFFFFF") + "\r";
        }

        /* internal  */getIconTip(): string
        {
            return HTMLUtil.addColor("Icon:" + this.itemInfo.item.icon, "#FFFFFF") + "\r";
        }

        /* internal  */getBindTip(): string
        {
            var loc1=this.itemInfo.item.bind;
            switch (loc1) 
            {
                case EBind._EBindAfterUse:
                {
                    return HTMLUtil.addColor("玩家使用后绑定", "#006600") + "\r";
                }
                case EBind._EBindYes:
                {
                    return HTMLUtil.addColor("已经绑定", "#00FF00") + "\r";
                }
                case EBind._EBindNo:
                {
                    return HTMLUtil.addColor("未绑定", "#444444") + "\r";
                }
                default:
                {
                    return HTMLUtil.addColor("未绑定", "#444444") + "\r";
                }
            }
        }

        public isSameItem(arg1: ItemData): Boolean
        {
            return arg1.category == this.category && arg1.type == this.type;
        }

        public isCanCD(): Boolean
        {
            return this.category == ECategory._ECategoryDrug && this.effect >= 0 && this.effect <= 2 || this.category == ECategory._ECategoryProp && this.type == EProp._EPropPassToCity;
        }

        public get effect(): int
        {
            if (this.itemInfo) 
            {
                return this.itemInfo.item.effect;
            }
            return -1;
        }

        public static /* const */nullItemData: ItemData=new ItemData(null);

        public static /* const */ToolTipType_Pack: int=0;

        public static /* const */ToolTipType_Mounts: int=1;

        public static /* const */ToolTipType_Player: int=2;

        public static /* const */ToolTipType_Forge: int=3;

        public static /* const */ToolTipType_Exchange: int=4;

        public static /* const */ToolTipType_PetEquip: int=5;

        public static /* const */ToolTipType_PetLifeStyle: int=6;

        public static /* const */ToolTipType_PetLifeStyleEquip: int=7;

        public static /* const */ToolTipType_MountEquip: int=8;

        public /* var */isFaultMagicWeapon: Boolean=false;

        /* internal */ /* var */_data: SPlayerItem;

        /* internal */ /* var */_itemInfo: ItemInfo;

        /* internal */ /* var */_itemExInfo: ItemExInfo;

        public /* var */effectName: string;

        /* internal */ /* var */_cdTime: number=-1;

        /* internal */ /* var */_gasValue: int;

        /* internal */ /* var */_name: string;

        /* internal */ /* var */_url: string;

        public /* var */additionalInfo: Object;

        public /* var */equipmentToolTipData: EquipmentToolTipData;

        public /* var */petEquipmentToolTipData: PetEquipTooltipInfo;

        public /* var */mountEquipmentToolTipData: MountEquipToolTipInfo;

        /* internal */ /* var */_modelId: string;

        /* internal */ /* var */_color: int;

        /* internal */ /* var */_refLockDic: Map<any, any> /* flash.utils.Dictionary */;
    }
